﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace winform基础学习
{
    public partial class Index : Form
    {
        public Index(UserTModel model)
        {
            InitializeComponent();
            label1.Text = $"欢迎你，{model.NickName}!";
        }

        private void Index_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void Index_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns=false;
            List<UserTModel> listUsers = null;
            using (MyDbContext myDbContext = new MyDbContext())
            {
                listUsers= myDbContext.userTModels.ToList();
            }
            dataGridView1.DataSource = listUsers;
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex == 4)
            {
                //获取当前的用户名
               string userName = dataGridView1.Rows[e.RowIndex].Cells["UserName"].Value.ToString().Trim();
                //弹出编辑窗口
                EditForm editForm=new EditForm(userName, Index_Load);
                editForm.ShowDialog();
            }
        }
    }
}
